(use-modules
 ;; for unit testing forms
 (srfi srfi-64))

(use-modules
 ;; import the module to test
 (set))

(test-begin "set-test")

(test-group
 "set-test-group"

 (test-assert "set contains added items"
   (let* ([my-set (make-set '())]
          [added-item 'bla])
     (set-add! my-set added-item)
     (set-in? my-set added-item)))

 (test-assert "set contains multiple added items"
   (let ([my-set (make-set '())])
     (set-add! my-set 1)
     (set-add! my-set 2)
     (set-add! my-set 3)
     (and (set-in? my-set 1)
          (set-in? my-set 2)
          (set-in? my-set 3))))

 (test-assert "set does not contain removed items"
   (let ([my-set (make-set '())])
     (set-add! my-set 1)
     (set-add! my-set 2)
     (set-add! my-set 3)
     (set-remove! my-set 2)
     (and (set-in? my-set 1)
          (not (set-in? my-set 2))
          (set-in? my-set 3))))

 (test-assert "set union contains elements of all merged sets"
   (let ([my-set-1 (make-set '())]
         [my-set-2 (make-set '())])
     (set-add! my-set-1 1)
     (set-add! my-set-1 2)
     (set-add! my-set-1 3)
     (set-add! my-set-2 1)
     (set-add! my-set-2 5)
     (set-add! my-set-2 6)
     (let ([uni (set-union my-set-1 my-set-2)])
       (and (set-in? uni 1)
            (set-in? uni 2)
            (set-in? uni 3)
            (set-in? uni 5)
            (set-in? uni 6)))))

 (test-assert "set union of more than 2 sets contains elements of all merged sets"
   (let ([my-set-1 (make-set '())]
         [my-set-2 (make-set '())]
         [my-set-3 (make-set '())])
     (set-add! my-set-1 1)
     (set-add! my-set-1 2)
     (set-add! my-set-1 3)
     (set-add! my-set-2 1)
     (set-add! my-set-2 5)
     (set-add! my-set-2 6)
     (set-add! my-set-3 4)
     (let ([uni (set-union my-set-1 my-set-2 my-set-3)])
       (and (set-in? uni 1)
            (set-in? uni 2)
            (set-in? uni 3)
            (set-in? uni 4)
            (set-in? uni 5)
            (set-in? uni 6))))))

(test-end "set-test")
